package com.binhthuan.catechist.client.data;

import com.binhthuan.catechist.shared.constant.Parameter;
import com.binhthuan.catechist.shared.constant.Service;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;

public class PlanDetailDS extends AbstractDS {

    private static PlanDetailDS instance;

    private PlanDetailDS() {
        super(Service.PLAN_DETAIL);

        DataSourceIntegerField id = new DataSourceIntegerField(Parameter.ID);
        id.setPrimaryKey(true);
        id.setHidden(true);

        DataSourceTextField content = new DataSourceTextField(Parameter.CONTENT);
        DataSourceTextField comment = new DataSourceTextField(Parameter.COMMENT);

        DataSourceTextField date = new DataSourceTextField(Parameter.DATE);
        date.setValueXPath(combineXPath(Parameter.DATE, Parameter.ID));
        date.setTypeAsDataSource(DateDS.getInstance());

        DataSourceTextField plan = new DataSourceTextField(Parameter.PLAN);
        plan.setValueXPath(combineXPath(Parameter.PLAN, Parameter.ID));
        plan.setTypeAsDataSource(PlanDS.getInstance());

        setFields(id, content, comment, date, plan);
    }

    public static PlanDetailDS getInstance() {
        if (instance == null) {
            instance = new PlanDetailDS();
        }
        return instance;
    }
}
